The amount of times I look these up...
I have screenshots saved, I have notes...
Yea, I'll be adding to this list. Until then...
$ git checkout -b branch-name-here
switches to new branch 'branch-name-here'
Shortcut for:
$ git branch branch-name-here
$ git checkout branch-name-here
$ git checkout master
$ git pull
$ git checkout other-branch
$ git rebase master
$ git push origin other-branch -f
$ git branch -d the-local-branch
This one I actually only used once and I'm not exactly sure what was the situation, but I jotted it down nonetheless because, well, you never know. There are two posts I saved regarding this topic-- perhaps, I'll look them over and summarize them here or on a seperate post.
$ git clean -n
(will show files that would be deleted)
$ git clean -f
(will delete files)
$ git reset --hard master@{"300 minutes ago"}
to revert back to a certain period of time... before you screwed up :D
That^ little nugget of wisdom came from @data_stephanie on Twitter. I love Twitter
$ git reset --hard HEAD^
undo without keeping changes made
$ git reset --soft HEAD^
undo keeps changes BEFORE commit
First time using this one was to remove a few deleted files.
$ git add -u
stages already tracked files, does not add new files
git log
situation?ready? press Q
key. Yep.
$ git commit --amend
that will open editor or git commit --amend -m "new commit message here"
straight from terminal.
link below gives more detail and talks of modifying commit message when already pushed.
git stash
?check out the stash using git stash list
for the latest stash, git stash apply
and for a non-recent stash... it will look something like git stash apply stash@{2}
the number will depend on what is displayed when you check out the list and which one of those you want to apply. Note: using no number, it will be assumed it is the latest stash you're looking to apply.
how about gettin' rid of that stash?
git stash drop
drops the top stash, while git stash drop stash@{2}
gets rid of a specific stash. Note: the '2' is just for example, it can be whatever number that points to the specific stash your heart desires.
create a new branch, $ git branch branch-name-here
, from where you've made all the commits, in my case it was master
make sure you're on whatever branch you made the mistake commits too... make sure... are you sure? Ok.
$ git reset --hard 8abc8ab
the characters after --hard
will be the commit you'd like to revert to.
This will revert the branch you accidentally commited to back to the point(commit) before the screw up :D Note: you can use first 7 characters of the commit, they can be forever long
git pull --rebase
adds your new commit on top, at this point you should see some stuff in your terminal saying to re-push your awesome :D; your github should show commits in the order expected
sometimes this happens where an editor will show up that (if you've never seen before) may leave you staring at the screen all 'dafuq-like'.
If you happen to go this route:
That gem of info (list) came from this SO post
Hello git clone
! Put that into your terminal, at your desired location, and follow it with url that shows up when you click that "clone or download" green button on repo's page. See this nice post by Github :)
Resource: Forking vs. Cloning repo
git reset --hard <commit-hash>
git push -f origin master
Note: DO NOT do this if you have a repo with collaborators who may have pulled and started working. At that point it may be best to create a branch with what you want back on there to then be merged into master repo. That way everyone pulls that update with their possible additions jazz and things :D
Resource: Resetting Remote to a Certain Commit
Diverged Branches SO Link has a few links to look into within the accepted answer.
git add <file>
git rebase --continue
Resource: After Fixing Conflicts Git Still Complains
One day you may find yourself needing to keep things seperate... work and personal accounts for instance.
Reference:
Note: One thing I noticed when I had to do this some time after setup-- if I wasn't cloning but creating you still have to make sure you differentiate cmd as would with cloning and check/change user/email associated to gh acct desired.
git config --list
to check username/email for particular project
git remote set-url origin git://new.url.here
Reference: how-to-remove-remote-origin-from-git-repo
Note: SSH keys get deleted after a certain period of inactivity pbcopy < ~/.ssh/someName.pub
-- if you have .pub
files you're able to copy this to connect to GitHub
Not limited to remote on another machine.
cd {repo to update}
git remote add {path of repo cherry-picking from}
You can fetch
and cherry-pick
commits to transfer, ie: git cherry-pick abc6666^..xyz8888
. Note: the use of the ^
is to include that first commit in the range, otherwise it will start the following commit in the range
Regarding cherry-pick
:
If you press git cherry-pick --continue
and you have resolved conflicts and added files and all that jazz... you may see something that looks like could be an error when in fact it is your default editor.
Navigate using:
Reference:
git log --oneline --graph
Below discoveries came from looking up warning: LF will be replaced by CRLF in <whatever file>
which apparently happens when working on a Windows machine, although I had never seen it before this moment shrugs anywaaay...
git init .
rm -rf .git
git add .
git rm -r --cached .
What I ended up doing for my initial issue: git config --local core.autocrlf false
there's like a whole thing to this... I mean a whole thing where there's arguments to both sides, true and false. Instead of the rabbit hole I would have for sure continued on I decided on that and moved on. Although, I'd be lying if I didn't say... I'm curious.
I ended up not ignoring a file I should have and then realized it after a few commits... luckily, there is...
git filter-branch
; Resource: https://help.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository
Note: if it doesn't seem to work, check file path